﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
using Manager.CustomerHelper;
namespace HealthSystem
{
    public partial class School_New : BasePage
    {
        HW_SchoolManager manager = new HW_SchoolManager();
        public override ModuleType Module
        {
            get
            {
                return ModuleType.SchoolManager;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TextBox2.OnClientTriggerClick = Window1.GetSaveStateReference(orgcode.ClientID, TextBox2.ClientID)
                  + Window1.GetShowReference("./ChooseOrg.aspx","选择体检机构");
                Button2.OnClientClick = Window2.GetSaveStateReference(districtname.ClientID,districtid.ClientID)
                  + Window2.GetShowReference("sysadmin/dischoose.aspx","地区选择");
                btnClose.OnClientClick = ActiveWindow.GetConfirmHidePostBackReference();
            }
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            
                //string code="888888";
                //RSAHelper rsa = new RSAHelper();
                //rsa.Initial(code);

                string pdistrictId = districtid.Text;
                if (string.IsNullOrEmpty(pdistrictId))
                {
                    Alert.Show("区域不能为空");
                    return;
                }
                //if (string.IsNullOrEmpty(orgcode.Text))
                //{
                //    Alert.Show("体检机构不能为空");
                //    return;
                //}
                Random rd = new Random();
                HW_DistrictManager dismanager = new HW_DistrictManager();
                string cityid = dismanager.GetById(pdistrictId).ParentDistrictCode ;
                HW_School org = new HW_School();
                //org.SchoollCode = pdistrictId + DateTime.Now.Year.ToString().Substring(1, DateTime.Now.Year.ToString().Length - 1) + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Millisecond.ToString().PadLeft(3, '0') + newUserId.ToString().PadLeft(5, '0');
                org.SchoollCode = pdistrictId + DateTime.Now.Year.ToString().Substring(1, DateTime.Now.Year.ToString().Length - 1) + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Millisecond.ToString().PadLeft(3, '0') + rd.Next(10000,99999).ToString();
                org.DistrictCode = districtid.Text;
                org.CityId = cityid;
                org.Name = name.Text;
                org.SchoolType = stype.SelectedText;
                org.OrgCode = orgcode.Text;
                org.Address = Address.Text;
                org.LinkMan = LinkMan.Text;
                org.OfficePhone = OfficePhone.Text;
                org.MobilePhone = MobilePhone.Text;
                org.Email = Email.Text;
                bool permit = permitcheck.Checked;
                try
                {
                    manager.Add(org, permit, schoolcheck.Checked);
                    Alert.Show(org.Name + "新增成功");
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                catch
                {
                    Alert.Show("新增学校出错");
                }
        }
    }
}